//
//  RequestManager.m
//  MusicDemo
//
//  Created by lanou on 16/6/15.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "RequestManag.h"
@interface RequestManag()
@property (nonatomic,strong)NSMutableArray *musicArray;//存放数据的

@end

@implementation RequestManag
//单例
+ (RequestManager *)creatRequest {
    static RequestManager *request = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        request = [[RequestManager alloc]init];
    });
    return request;
}
- (NSMutableArray *)musicArray{
    if (!_musicArray) {
        _musicArray = [NSMutableArray array];
    }
    return _musicArray;
}
//通过url获取数据
- (void)fetchDataWithUrl:(NSString *)url updateUI:(musicBlock)block {
    
    //子线程，用来处理耗时操作
//    dispatch_async(dispatch_get_global_queue(0,0), ^{
//        NSArray *arr = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:url]];
//       
//        for (NSDictionary *dic in arr) {
//            
//            Music *music = [[Music alloc]init];
//            [music setValuesForKeysWithDictionary:dic];
//            [self.musicArray addObject:music];
//            NSLog(@"%@",dic);
//        }
//        //主线程 主要用来刷新UI
//        dispatch_async(dispatch_get_main_queue(), ^{
//            
//            block();
//            NSLog(@"刷新UI");
//        });
//        
//    });
}

//返回数据个数
- (NSInteger)returnArrayCount {
    return self.musicArray.count;
}
//返回对应下标的模型
- (Music *)returnMusicAtIndex:(NSInteger)index {
    return self.musicArray[index];
}


@end
